﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BLL
{
    public class AbsenseNotifier
    {
        public AbsenseNotifier()
        {
            foreach (Trainee trainee in TraineeManager.Instance.GetTrainees())
            {
                DateTime? lastVisit = TraineeManager.Instance.GetLastVisiting(trainee.TraineeId);
                if (lastVisit == null)
                {
                    continue;
                }

                DateTime now = DateTime.Now;
                if (DateTime.Compare(now, lastVisit.Value.AddDays(14)) > 0)
                {
                    if (trainee.AbsenseNotificationSent == false)
                    {
                        sentNotification(trainee);
                        TraineeManager.Instance.UpdateAbsenseNotification(trainee, true);
                    }
                }
            }
        }

        private void sentNotification(Trainee i_Trainee)
        {
            try
            {
                EmailService.SendEmail("Subject1", "body1", i_Trainee.Email);
            }
            catch (Exception)
            {
                
                throw;
            }
        }
    }
}
